<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Lexar</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.code {
    white-space: pre;
    font-family: 'Consolas';
    font-size: 14pt;
}
._lex_String {
    color: #00AA00;
}
._lex_Comment {
    color: #AAAAAA;
    font-style: italic;
}
._lex_QName {
    font-weight: bold;
}
._lex_Assign,
._lex_OpenSquare,
._lex_CloseSquare,
._lex_OpenFig,
._lex_CloseFig {
    color: #CCCCCC;
}
</style>
</head>
<body>
<?php

class xsd_anyType
{

}

class xsd_anySimpleType extends xsd_anyType
{

}

class xsd_string extends xsd_anySimpleType
{
    public function toString()
    {
        return '';
    }
}

class xsd_boolean extends xsd_anySimpleType
{
    private $_M_value;

    public function __construct($string)
    {
        $this->_M_value = _parse($string);
    }

    protected function _parse($string)
    {
        if (($string === 'true') || ($string === '1')) {
            return true;
        } elseif (($string === 'false') || ($string === '0')) {
            return false;
        } else {
            throw new Exception();
        }
    }

    public function toString()
    {
        return '';
    }
}

class xsd_base64Binary extends xsd_anySimpleType
{

}

class xsd_hexBinary extends xsd_anySimpleType
{

}

class xsd_float extends xsd_anySimpleType
{

}

class xsd_decimal extends xsd_anySimpleType
{

}

class xsd_double extends xsd_anySimpleType
{

}

class xsd_anyURI extends xsd_anySimpleType
{

}

class xsd_QName extends xsd_anySimpleType
{

}

class xsd_NOTATION extends xsd_anySimpleType
{

}

class xsd_duration extends xsd_anySimpleType
{

}

class xsd_dateTime extends xsd_anySimpleType
{

}

class xsd_time extends xsd_anySimpleType
{

}

class xsd_date extends xsd_anySimpleType
{

}

class xsd_gYearMonth extends xsd_anySimpleType
{

}

class xsd_gYear extends xsd_anySimpleType
{

}

class xsd_gMonthDay extends xsd_anySimpleType
{

}

class xsd_gDay extends xsd_anySimpleType
{

}

class xsd_gMonth extends xsd_anySimpleType
{

}

class xsd_noramlizedString extends xsd_string
{

}

class xsd_token extends xsd_noramlizedString
{

}

class xsd_language extends xsd_token
{

}

class xsd_Name extends xsd_token
{

}

class xsd_NMTOKEN extends xsd_token
{

}

class xsd_NCName extends xsd_name
{

}

class xsd_ID extends xsd_NCName
{

}

class xsd_IDREF extends xsd_NCName
{

}

class xsd_ENTITY extends xsd_NCName
{

}

class xsd_IDREFS //extends xsd_List
{

}

class xsd_ENTITIES //extends xsd_List
{

}

class Lexeme
{
    public $name;
    public $value;

    function __construct($name, $value = '')
    {
        $this->name  = $name;
        $this->value = $value;
    }

    function name()
    {
        return '';
    }

    function value()
    {
        return '';
    }

    function toString()
    {
        $result = '';
        switch ($this->name) {
            case 'Comment':
                $result .= '/*';
                $result .= $this->value;
                $result .= '*/';
                break;

            case 'String':
                $result .= '"';
                $result .= $this->value;
                $result .= '"';
                break;

            case 'Assign':
                $result .= '=';
                break;

            case 'OpenSquare':
                $result .= '[';
                break;

            case 'CloseSquare':
                $result .= ']';
                break;

            case 'OpenFig':
                $result .= '{';
                break;

            case 'CloseFig':
                $result .= '}';
                break;

            default:
                $result = $this->value;
        }
        return $result;
    }
}

class Stream
{
    protected $IsNotEnd;
    protected $stream;
    protected $position;

    function __construct($string)
    {
        $this->steam = $string;
        $this->position = 0;
        $this->IsNotEnd = (bool) strlen($this->steam);
    }

    function Next()
    {
        if ($this->position < (strlen($this->steam) - 1)) {
            $this->position++;
        } else {
            $this->IsNotEnd = false;
        }
    }

    function Ch()
    {
        return $this->steam[$this->position];
    }

    function IsNotEnd()
    {
        return $this->IsNotEnd;
    }
}

class Lex
{
    protected $Lexeme;
    protected $IsNotEnd;
    protected $stream;
    protected $stack;

    function __construct()
    {
        $this->stack = array();
    }

    function SetStream(Stream $stream)
    {
        $this->stream = $stream;
        $this->IsNotEnd = $stream->IsNotEnd();
        if ($this->IsNotEnd()) {
            $this->Next();
        }
    }

    function Next()
    {
    }

    function Lexeme()
    {
        return $this->Lexeme;
    }

    function IsNotEnd()
    {
        return $this->IsNotEnd;
    }
}

class XCodeLex extends Lex
{
    function Next()
    {
        if ($this->stream->IsNotEnd()) {
            switch (true) {
                case $this->firstString():
                    $this->Lexeme = new Lexeme('String', $this->dString());
                    break;

                case $this->firstComment():
                    $this->Lexeme = new Lexeme('Comment', $this->dComment());
                    break;

                case $this->firstS():
                    $this->Lexeme = new Lexeme('S', $this->dS());
                    break;

                case $this->firstQName():
                    $this->Lexeme = new Lexeme('QName', $this->dQName());
                    break;

                case $this->stream->Ch() == '=':
                    $this->Lexeme = new Lexeme('Assign');
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        $this->IsNotEnd = false;
                    }
                    break;

                case $this->stream->Ch() == '[':
                    $this->Lexeme = new Lexeme('OpenSquare');
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        $this->IsNotEnd = false;
                    }
                    break;

                case $this->stream->Ch() == ']':
                    $this->Lexeme = new Lexeme('CloseSquare');
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        $this->IsNotEnd = false;
                    }
                    break;

                case $this->stream->Ch() == '{':
                    $this->Lexeme = new Lexeme('OpenFig');
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        $this->IsNotEnd = false;
                    }
                    break;

                case $this->stream->Ch() == '}':
                    $this->Lexeme = new Lexeme('CloseFig');
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        $this->IsNotEnd = false;
                    }
                    break;

                default:
                    throw new Exception($this->stream->Ch());
            }
        } else {
            $this->IsNotEnd = false;
        }
        if (! $this->stream->IsNotEnd()) {
            $this->IsNotEnd = false;
        }
    }

    function dString()
    {
        $value = '';
        if ($this->stream->Ch() == '"') {
            if ($this->stream->IsNotEnd()) {
                $this->stream->Next();
                while ($this->stream->Ch() != '"') {
                    if ($this->stream->Ch() != '\\') {
                        $value .= $this->stream->Ch();
                    } else {
                        if ($this->stream->IsNotEnd()) {
                            $this->stream->Next();
                            if ($this->stream->Ch() == 'n') {
                                $value .= "\n";
                            } elseif ($this->stream->Ch() == 'r') {
                                $value .= "\r";
                            } elseif ($this->stream->Ch() == 't') {
                                $value .= "\t";
                            } elseif ($this->stream->Ch() == '\\') {
                                $value .= "\\";
                            } elseif ($this->stream->Ch() == '"') {
                                $value .= '"';
                                /*
                                \[0-7]{1,3}
                                \x[0-9A-Fa-f]{1,2}
                                */
                            } else {
                                throw new Exception();
                            }
                        } else {
                            throw new Exception();
                        }
                    }
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        throw new Exception();
                    }
                }
                if ($this->stream->IsNotEnd()) {
                    $this->stream->Next();
                }
                return $value;
            } else {
                throw new Exception();
            }
        } else {
            if ($this->stream->IsNotEnd()) {
                $this->stream->Next();
                while ($this->stream->Ch() != "'") {
                    if ($this->stream->Ch() != '\\') {
                        $value .= $this->stream->Ch();
                    } else {
                        if ($this->stream->IsNotEnd()) {
                            $this->stream->Next();
                            if ($this->stream->Ch() == '\\') {
                                $value .= "\\";
                            } elseif ($this->stream->Ch() == "'") {
                                $value .= "'";
                            } else {
                                throw new Exception();
                            }
                        } else {
                            throw new Exception();
                        }
                    }
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        throw new Exception();
                    }
                }
                if ($this->stream->IsNotEnd()) {
                    $this->stream->Next();
                }
                return $value;
            } else {
                throw new Exception();
            }
        }
    }

    function dComment()
    {
        $value = '';
        if ($this->stream->IsNotEnd()) {
            $this->stream->Next();
            if ($this->stream->Ch() == "*") {
                if ($this->stream->IsNotEnd()) {
                    $this->stream->Next();
                } else {
                    throw new Exception();
                }
                while (true) {
                    while ($this->stream->Ch() != "*") {
                        $value .= $this->stream->Ch();
                        if ($this->stream->IsNotEnd()) {
                            $this->stream->Next();
                        } else {
                            throw new Exception();
                        }
                    }
                    if ($this->stream->IsNotEnd()) {
                        $this->stream->Next();
                    } else {
                        throw new Exception();
                    }
                    if ($this->stream->Ch() == "/") {
                        if ($this->stream->IsNotEnd()) {
                            $this->stream->Next();
                        }
                        return $value;
                    } else {
                        $value .= '*'.$this->stream->Ch();
                        if ($this->stream->IsNotEnd()) {
                            $this->stream->Next();
                        } else {
                            throw new Exception();
                        }
                        continue;
                    }
                }
            } else {
                throw new Exception();
            }
        } else {
            throw new Exception();
        }

    }

    function dQName()
    {
        $value = '';
        if ($this->stream->IsNotEnd()) {
            while (($this->stream->Ch() >= 'a' && $this->stream->Ch() <= 'z') || ($this->stream->Ch() >= 'A' && $this->stream->Ch() <= 'Z') || in_array($this->stream->Ch(), array(':', '_', '-', '.'))) {
                $value .= $this->stream->Ch();
                if ($this->stream->IsNotEnd()) {
                    $this->stream->Next();
                } else {
                    break;
                }
            }
        }
        return $value;
    }

    function dS()
    {
        $value = '';
        if ($this->stream->IsNotEnd()) {
            while (in_array($this->stream->Ch(), array("\x20", "\x9", "\xD", "\xA"))) {
                $value .= $this->stream->Ch();
                if ($this->stream->IsNotEnd()) {
                    $this->stream->Next();
                } else {
                    break;
                }
            }
        }
        return $value;
    }

    function firstString()
    {
        return in_array($this->stream->Ch(), array('"', "'"));
    }

    function firstComment()
    {
        return $this->stream->Ch() == '/';
    }

    function firstS()
    {
        return in_array($this->stream->Ch(), array("\x20", "\x9", "\xD", "\xA"));
    }

    function firstQName()
    {
        return $this->firstNCName();
    }

    function firstNCName()
    {
        return ($this->stream->Ch() >= 'a' && $this->stream->Ch() <= 'z') || ($this->stream->Ch() >= 'A' && $this->stream->Ch() <= 'Z') || in_array($this->stream->Ch(), array(':', '_', '-', '.'));
    }
}


/*
<simpleType
  final = (#all | (list | union | restriction))
  id = ID
  name = NCName
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (restriction | list | union))
</simpleType>

<restriction
  base = QName
  id = ID
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*))
</restriction>

<list
  id = ID
  itemType = QName
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (simpleType?))
</list>

<union
  id = ID
  memberTypes = List of QName
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (simpleType*))
</union>
*/

$XSL_for_XMLSchema = <<<XSL_for_XMLSchema
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transforms"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsl:template match="simpleType">

    </xsl:template>

    <xsl:template match="restriction">

    </xsl:template>

    <xsl:template match="list">

    </xsl:template>

    <xsl:template match="union">

    </xsl:template>

</xsl:stylesheet>
XSL_for_XMLSchema;

	    $xsl = new DOMDocument();
	    $xsl->loadXML($XSL_for_XMLSchema);

$XSL_for_XMLSchema = <<<XSL_for_XMLSchema
xsl:stylesheet [
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transforms"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"]
{

    xsl:template [match="simpleType"] {

    }

    xsl:template [match="restriction"] {

    }

    xsl:template [match="list"] {

    }

    xsl:template [match="union"] {

    }

}}
XSL_for_XMLSchema;

$stream = new Stream($XSL_for_XMLSchema);
$lax = new XCodeLex();
$lax->SetStream($stream);
$count = 0;
echo "<div class=\"code\">";
while ($lax->IsNotEnd()) {
    $lexeme = $lax->Lexeme();
    echo "<span class=\"_lex_{$lexeme->name}\">" . htmlspecialchars($lexeme->toString()) . "</span>";
    $lax->Next();
    if ($count++ > 100) {
        break;
    }
}
echo "</div>";


?>
</body>
</html>